trigger readAccessOnQueueNotes on Lead (after update) {
          
  ListViewIds__c LV = ListViewIds__c.getInstance();   
  Id SfaNJQueueId  = LV.SFA_OOR_New_Jersey_Sharkpool__c;    
  Id SfaSLCQueueId = LV.SFA_OOR_Salt_Lake_Sharkpool__c;
  Map <id,id> QueueLeadsMapID = new Map<id,id>();
  Map <id,id> leadsIntoQueueMapID = new Map<id,id>();
  Map<id,id> secondaryOwnerIds = new map<id,id>();   
  
  for(lead l:trigger.new){                                
        if(l.ownerid != trigger.oldMap.get(l.id).ownerid){                              
               // when lead is moving into Queue from user , share it with all public group               
               if(l.ownerid == SfaNJQueueId || l.ownerid == SfaSLCQueueId){       
                      leadsIntoQueueMapID.put(l.id,l.ownerid); 
                        }
              //when lead is moving from Queue to user, unshare with other public group and share with new user         
               else if(trigger.oldMap.get(l.id).ownerid == SfaSLCQueueId || trigger.oldMap.get(l.id).ownerid == SfaNJQueueId){ 
                      QueueLeadsMapID.put(l.id,l.ownerid);                  
                      }                         
          }
         if(l.Secondary_Owner__c!=null){
             if(l.Secondary_Owner__c != trigger.oldMap.get(l.id).Secondary_Owner__c){
                 secondaryOwnerIds.put(l.id,l.secondary_owner__c);
             }
         }
  }
  
  if(QueueLeadsMapID.size()>0) customSharingClass.NotesOwnerId(QueueLeadsMapID);  
  if(leadsIntoQueueMapID.size()>0) customSharingClass.LeadsNotesintoQueue(leadsIntoQueueMapID);                 
  if(secondaryOwnerIds.size()>0) customSharingClass.leadSecondaryOwnerNotesShare(secondaryOwnerIds,trigger.oldMap);
}